package com.Smart.smartscals.DataBase;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;


public class TimeDateUtils {

	public static final int ONE_WEEK_DATA = 0;
	public static final int ONE_MONTH_DATA = 1;
	public static final int THREE_MONTH_DATA = 2;
	public static final int SIX_MONTH_DATA = 3;
	public static final int ONE_YEAR_DATA = 4;

	//get cur time by long format
	public static long getCurDate(){
		Calendar c = Calendar.getInstance();
		return c.getTimeInMillis();}


	//set the from date to 0 hour/0 minute/0 second
	public static long setFromDate(Calendar cal){
		Calendar mcalendar = cal;
		mcalendar.set(Calendar.HOUR_OF_DAY, 0);
		mcalendar.set(Calendar.MINUTE, 0);
		mcalendar.set(Calendar.SECOND, 0);
		mcalendar.set(Calendar.MILLISECOND, 0);
		return mcalendar.getTimeInMillis();
	}

	//set the to date to 23:59:59
	public static long setToDate(Calendar cal){
		Calendar mcalendar = cal;
		mcalendar.set(Calendar.HOUR_OF_DAY, 23);
		mcalendar.set(Calendar.MINUTE, 59);
		mcalendar.set(Calendar.SECOND, 59);
		mcalendar.set(Calendar.MILLISECOND, 0);		
		return mcalendar.getTimeInMillis();
	}

	//get the days between two long date
	public static int getIntervalDays(long paramLong1,long paramLong2){
		return (int)((paramLong1-paramLong2)/86400000L);
	}

	public static int getMinute(long paramLong){
		return (int) (paramLong/60000);
	}

	public static String convert2TopBarDate(long paramLong){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm",Locale.US);
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return sdf.format(localDate);
	}


	//convert long date to whole date
	public static String convert2WholeDate(long paramLong){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.US);
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return sdf.format(localDate);
	}
	public static long  strTime2LongTime(String strTime){
		long longtime=0L ;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			longtime = sdf.parse(strTime).getTime();
		
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}//毫秒
		return longtime;
	}
	public static long  strTimeCovLongTime(String strTime){
		long longtime=0L ;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			longtime = sdf.parse(strTime).getTime();
		
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}//毫秒
		return longtime;
	}


	public static String convert2FileDate(long paramLong){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss",Locale.CHINA);
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return sdf.format(localDate);
	}
	public static String convert2FileName(long paramLong){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss",Locale.CHINA);
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return sdf.format(localDate);
	}

	public static String[] convert2DatArray(long paramLong){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy#MM#dd",Locale.CHINA);	
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return sdf.format(localDate).split("#");

	}
	public static String convert2FullDate(int year,int month,int day,int hour,int minute,int second){
		Calendar cal = Calendar.getInstance();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month-1);
		cal.set(Calendar.DAY_OF_MONTH, day);
		cal.set(Calendar.HOUR_OF_DAY, hour);
		cal.set(Calendar.MINUTE, minute);
		cal.set(Calendar.SECOND, second);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss",Locale.US);
		Date localDate = new Date();
		localDate.setTime(cal.getTimeInMillis());
		return sdf.format(localDate);
	}	

	public static String convert2DateBarDate(long paramLong){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年M月d日",Locale.US);
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return sdf.format(localDate);
	}

	public static String convert2ListFormatDate(long paramLong){
		SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm",Locale.US);
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return sdf.format(localDate);
	}

	public static int getHourFromLongDate(long paramLong){
		Calendar cal = Calendar.getInstance();
		Date localDate = new Date();
		localDate.setTime(paramLong);
		cal.setTime(localDate);
		return cal.get(Calendar.HOUR_OF_DAY);
	}

	//convert long date to string date
	public static String convert2StringDate(long paramLong,SimpleDateFormat sdf){
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return sdf.format(localDate);
	}

	//get long date base on a long date and a int days
	public static Long getLongWithDays(long paramLong,int paramInt){
		return paramLong + paramInt * 86400000L;
	}

	//convert long date to string date without year 
	public static String convert2SimpleDate(long paramLong){
		SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd",Locale.US);
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return dateFormat.format(localDate);
	}

	public static String convert2SimpleTimeStr(long paramLong){
		SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm",Locale.US);
		Date localDate = new Date();
		localDate.setTime(paramLong);
		return dateFormat.format(localDate);
	}

	//convert Integers to long like 1986 2 3 to 11122346546L
	public static long convert3IntValue(int paramInt1, int paramInt2, int paramInt3)
	{
		Calendar localCalendar = Calendar.getInstance();
		localCalendar.set(paramInt1, paramInt2, paramInt3);
		return localCalendar.getTimeInMillis();
	}

	public static long convert2LongDate(String strDate,SimpleDateFormat sdf){
		Date localDate;
		try { 
			localDate = sdf.parse(strDate);
			return localDate.getTime();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0L;
	}

	public static long getRangeFromDate(int range){
		Calendar fromCalendar = Calendar.getInstance();
		switch(range){
		case ONE_WEEK_DATA:
			fromCalendar.add(Calendar.DATE, -7);
			return setFromDate(fromCalendar);
		case ONE_MONTH_DATA:
			fromCalendar.add(Calendar.DATE, -30);
			return setFromDate(fromCalendar);
		case THREE_MONTH_DATA:
			fromCalendar.add(Calendar.DATE, -90);
			return setFromDate(fromCalendar);
		case SIX_MONTH_DATA:
			fromCalendar.add(Calendar.DATE, -180);
			return setFromDate(fromCalendar);
		case ONE_YEAR_DATA:
			fromCalendar.add(Calendar.DATE, -365);
			return setFromDate(fromCalendar);
		}
		return 0;
	}



}
